package com.study.rabbitmq.workQueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.study.rabbitmq.utils.RabbitMqUtil;

import java.io.IOException;
import java.util.Scanner;

public class Production {
    private static final String QUEUE_NAME = "queue";

    public static void main(String[] args) throws IOException {
        Channel channel = RabbitMqUtil.getChannel();
        Scanner scanner = new Scanner(System.in);
        //队列持久化
        boolean durable = true;
        channel.queueDeclare(QUEUE_NAME,durable,false,false,null);
        while (true){
            String message = scanner.nextLine();
            //交换机  路由键   当durable为true，即信道持久化之后，设置消息持久化  MessageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes());
            System.out.println("消息发送成功");
        }
    }
}
